"""
API响应格式化工具
"""
from django.http import JsonResponse

def api_response(success, message=None, status_code=200):
    """
    构造标准API响应
    :param success: 请求是否成功
    :param message: 返回消息
    :param status_code: HTTP状态码
    :return: JsonResponse对象
    """
    response_data = {
        "success": "true" if success else "false",
        "message": message or ("操作成功" if success else "操作失败")
    }
    return JsonResponse(response_data, status=status_code)